﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;
using DLV.Library.Utilities;

namespace DLV.Data.Entities
{
    public class ServiceController
    {
        public int InsertService(ServiceInfo info)
        {
            return SQL.InsertService(info.ServiceName, info.LocationId, info.Note, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status,info.PartnerId);
        }
        public void UpdateService(ServiceInfo info)
        {
            SQL.UpdateService(info.ServiceId, info.ServiceName, info.LocationId, info.Note, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status,info.PartnerId);
        }
        public void DeleteService(ServiceInfo info)
        {
            DeleteService(info.ServiceId);
        }
        public void DeleteService(int serviceId)
        {
            SQL.DeleteService(serviceId);
        }
        public ServiceInfo GetService(int serviceId)
        {
            return CBO.FillObject<ServiceInfo>(SQL.GetService(serviceId));
        }
        public List<ServiceInfo> ListService()
        {
            return CBO.FillCollection<ServiceInfo>(SQL.ListService());
        }

        public List<ServiceInfo> ListServiceByStatus(int status)
        {
            return ListService().Where(p=>p.Status==status).ToList();
        }
        public List<ServiceInfo> ListServiceByPartnerAndLocation(int partner,int locationId)
        {
            return CBO.FillCollection<ServiceInfo>(SQL.ListServiceByPartnerAndLocation(partner,locationId));
        }
        public DataTable SelectService()
        {
            return CBO.ConvertToDataTable(ListService(), typeof(ServiceInfo));
        }

        public Dictionary<object, object> ListServiceLookup()
        {
            var users = ListServiceByStatus((int)Globals.DocumentStatus.Use).OrderBy(p=>p.ServiceName);
            var dicusers = new Dictionary<object, object>();
            
            foreach (ServiceInfo info in users)
            {
                
                dicusers.Add(info.ServiceId, info.ServiceName);
            }
            return dicusers;
        }
    }
}
